<template>
    <div class="app-container">
        <div class="Search">
            <!--工具条-->
            <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
                <el-form :inline="true" :model="query">

                    <el-form-item>
                    <el-cascader ref="organTree" placeholder="所属组织" :props="props" :options="optionData" @change="selectOrgan" clearable collapse-tags filterable></el-cascader>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="query.params.name" placeholder="模板名称" />
                    </el-form-item>

                    <el-form-item>
                        <el-input v-model="query.params.desc" placeholder="模板描述" />
                    </el-form-item>
                   
                    <el-form-item>
                        <SelectTree placeholder="设备类型" :props="deviceTypeTree.props" :options="deviceTypeTree.optionData" :value="deviceTypeTree.valueIdSelect" :clearable="deviceTypeTree.isClearable" :accordion="deviceTypeTree.isAccordion" @getValue="getValueSelect($event)" />
                    </el-form-item>
                       

                    <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData">查询</el-button>
                    </el-form-item>
                    <el-form-item>
                    <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
                    </el-form-item>
            </el-form>
        </el-col>
    </div>

        <div class="block">
            <el-table
                    v-loading="listLoading"
                    :data="list"
                    element-loading-text="Loading"
                    border
                    fit
                    highlight-current-row
            >
                <el-table-column align="center" label="序号" width="95">
                    <template slot-scope="scope">
                        {{ scope.$index }}
                    </template>
                </el-table-column>

                <el-table-column label="模板名称" width="138">
                <template slot-scope="scope">
                {{ scope.row.name }}
                </template>
                </el-table-column>
                <el-table-column label="模板描述" width="138">
                <template slot-scope="scope">
                {{ scope.row.desc }}
                </template>
                </el-table-column>
                <el-table-column label="所属机构" width="138">
                <template slot-scope="scope">
                {{ scope.row.organId }}
                </template>
                </el-table-column>
                 <el-table-column label="设备类型" width="150">
                <template slot-scope="scope">
                {{ scope.row.deviceTypeId }}
                </template>
                </el-table-column>
               
            
                <el-table-column align="center" prop="created_at" label="操作">
                    <template slot-scope="scope">
                        <span class="el-tag el-tag--info el-tag--mini" style="cursor: pointer;" @click="handleEdit(scope.$index, scope.row)">
                          {{ scope.row.isSet?'保存':"修改" }}
                        </span>
                        <span v-if="!scope.row.isSet" class="el-tag el-tag--danger el-tag--mini" style="cursor: pointer;" @click="handleDelete(scope.$index, scope.row)">
                          删除
                        </span>
                      
                        <span  class="el-tag el-tag--success el-tag--mini" style="cursor: pointer;" @click="handleManageAisleDialogOpen(scope.$index, scope.row)">
                          查看货道
                        </span>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="block">
            <el-pagination
                    :current-page="currentPage"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
            />
        </div>

        <div class="block">
            <!--弹框-->
            <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible">
                <el-form :model="form">
                    <el-form-item v-if="addForVisible"  label="主键">
                        <el-input v-model="form.id" placeholder="主键"  auto-complete="off"/>
                    </el-form-item>
                                        <el-form-item label="模板名称">
                        <el-input v-model="form.name" placeholder="模板名称"  auto-complete="off"/>
                    </el-form-item>
                                        <el-form-item label="模板描述">
                        <el-input v-model="form.desc" placeholder="模板描述"  auto-complete="off"/>
                    </el-form-item>
                                       

                    <el-form-item label="所属机构">
                        <SelectTree placeholder="所属组织" :props="organTree.organProps" :options="organTree.organOptionData" :value="organTree.valueIdSelectOrgan" :clearable="organTree.isClearable" :accordion="organTree.isAccordion" @getValue="getOrganSelected($event)" />
                    </el-form-item>
                                               
                    <el-form-item label="所属机构" >
                        <SelectTree placeholder="设备类型" :props="deviceTypeTree.props" :options="deviceTypeTree.optionData" :value="deviceTypeTree.valueIdSelect" :clearable="deviceTypeTree.isClearable" :accordion="deviceTypeTree.isAccordion" @getValue="getDeviceTypeSelected($event)" />
                    </el-form-item>

                </el-form>

                <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="handleEditSave">确 定</el-button>
                </div>
            </el-dialog>
        </div>


       <div class="block">
            <!--弹框-->
            <el-dialog :title="titleMap[dialogStatus]" width="50%" :visible.sync="dialogItemFormVisible">
                <el-form :inline="true" :model="deviceAisleTemplateItem">

                    <el-form-item v-if="addForItemVisible" label="主键">
                        <el-input v-model="deviceAisleTemplateItem.id" placeholder="主键"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="货道名称">
                        <el-input v-model="deviceAisleTemplateItem.aisleName" placeholder="货道名称"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品编号">
                        <el-input v-model="deviceAisleTemplateItem.goodsId" placeholder="商品编号"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品名称">
                        <el-input @focus="handleSelectGoodsDialogOpen" v-model="deviceAisleTemplateItem.goodsName" placeholder="商品名称" suffix-icon="el-icon-circle-plus-outline" auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品规格">
                        <el-input v-model="deviceAisleTemplateItem.goodsSpec" placeholder="商品规格"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品产地">
                        <el-input v-model="deviceAisleTemplateItem.goodsProductPlace" placeholder="商品产地"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品单价(分)">
                        <el-input type="number" v-model="deviceAisleTemplateItem.goodsPrice" placeholder="商品单价(分)"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品成本(分)">
                        <el-input type="number" v-model="deviceAisleTemplateItem.goodsCost" placeholder="商品成本(分)"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品优惠价(分)">
                         <el-input type="number"  v-model="deviceAisleTemplateItem.goodsDiscountPrice" placeholder="商品优惠价(分)"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="最低价(分)">
                   
                        <el-input type="number"  v-model="deviceAisleTemplateItem.basePrice" placeholder="最低价(分)"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="商品图片">
                        <!-- <el-input v-model="deviceAisleTemplateItem.goodsImg" placeholder="商品图片"  auto-complete="off"/> -->
                        <el-image
                          style="width: 100px; height: 100px"
                          :src="deviceAisleTemplateItem.goodsImg"
                          :fit="fit"></el-image>
                    </el-form-item>
                   
                    <el-form-item label="货道容量">
            
                        <el-input type="number"  v-model="deviceAisleTemplateItem.printCount" placeholder="货道容量"  auto-complete="off"/>
                    </el-form-item>
                    <el-form-item label="货道类型">
                        <el-select v-model="deviceAisleTemplateItem.aisleType" placeholder="货道类型">
                            <el-option
                                    v-for="item in query.templateItemAisleTypeOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                                
                    <el-form-item label="是否热销">
                        <el-select v-model="deviceAisleTemplateItem.isHot" placeholder="是否热销">
                            <el-option
                                    v-for="item in query.templateItemIsHotOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="控制板号">

                         <el-input type="number" step="1"  v-model="deviceAisleTemplateItem.ctrlBoard" placeholder="控制板号"  auto-complete="off"/>
                    </el-form-item>
                     <el-form-item label="控制指令">
                         <el-input type="number" step="1" v-model="deviceAisleTemplateItem.ctrlCmd" placeholder="控制指令"  auto-complete="off"/>
                </el-form-item>
                <el-form-item label="货道状态">
                    <el-select v-model="deviceAisleTemplateItem.status" placeholder="货道状态">
                        <el-option
                                v-for="item in query.templateItemStatusOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="排序">
                     <el-input type="number"  v-model="deviceAisleTemplateItem.sort" placeholder="排序"  auto-complete="off"/>
                </el-form-item>
                           
                <el-form-item label="备注">
                    <el-input v-model="deviceAisleTemplateItem.remark" placeholder=""  auto-complete="off"/>
                </el-form-item>
                
                                            
                </el-form>

                <div slot="footer" class="dialog-footer">
                <el-button @click="dialogItemFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="handleTemplateItemEditSave">确 定</el-button>
                </div>
            </el-dialog>
        </div>

        <div>
            <el-dialog :title="titleMap[dialogStatus]" width="80%"  :visible.sync="dialogQueryItemsFormVisible">
                       

                        <div class="Search">
                        <!--工具条-->
                            <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
                                <el-form :inline="true" :model="query">
                                
                                    <el-form-item >
                                        <el-input v-model="query.deviceAisleTemplateItem.aisleName" placeholder="请输入货道名称"  auto-complete="off"/>
                                    </el-form-item>
                                    <el-form-item >
                                        <el-input v-model="query.deviceAisleTemplateItem.goodsName" placeholder="请输入商品名称"  auto-complete="off"/>
                                    </el-form-item>
                                    <el-form-item >
                                        <el-input v-model="query.deviceAisleTemplateItem.aisleType" placeholder="请输入货道类型"  auto-complete="off"/>
                                    </el-form-item>
                                    <el-form-item >
                                        <el-input v-model="query.deviceAisleTemplateItem.aisleType" placeholder="请输入货道状态"  auto-complete="off"/>
                                    </el-form-item>
                                     <el-form-item>
                                        <el-button type="primary" @click="handleQueryAisleTemplateItem">查询</el-button>
                                    </el-form-item>
                                     <el-form-item>
                                        <el-button type="success" @click="handleAddAisles">添加货道</el-button>
                                    </el-form-item>

                                </el-form>
                            </el-col>
                        </div>

                        <div class="block">
                            <el-table
                                    v-loading="listLoading"
                                    :data="deviceAisleTemplateItemList"
                                    element-loading-text="Loading"
                                    border
                                    fit
                                    highlight-current-row
                            >
                                <el-table-column align="center" label="序号" width="95">
                                    <template slot-scope="scope">
                                        {{ scope.$index }}
                                    </template>
                                </el-table-column>

                                <el-table-column label="货道名称" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.aisleName }}
                                </template>
                                </el-table-column>
                               
                                <el-table-column label="模板编号" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.templateId }}
                                </template>
                                </el-table-column>
                                <el-table-column label="所属机构" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.organId }}
                                </template>
                                </el-table-column>

                                <el-table-column label="商品编号" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsId }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品名称" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsName }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品图片" width="120">
                                <template slot-scope="scope">
                                
                                    <el-image
                                      style="width: 100px; height: 100px"
                                      :src="scope.row.goodsImg"
                                      ></el-image>
 
                                </template>
                                </el-table-column>
                                <el-table-column label="商品规格" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsSpec }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品产地" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsProductPlace }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品单价" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsPrice }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品成本" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsCost }}
                                </template>
                                </el-table-column>
                                <el-table-column label="商品优惠价" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.goodsDiscountPrice }}
                                </template>
                                </el-table-column>
                                <el-table-column label="最低价" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.basePrice }}
                                </template>
                                </el-table-column>

                                
                                <el-table-column label="打印数量" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.printCount }}
                                </template>
                                </el-table-column>
                                <el-table-column label="货道类型" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.aisleType }}
                                </template>
                                </el-table-column>
                                <el-table-column label="是否已删除" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.deleted }}
                                </template>
                                </el-table-column>
                                <el-table-column label="是否打印完成" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.isDone }}
                                </template>
                                </el-table-column>
                                <el-table-column label="是否热销" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.isHot }}
                                </template>
                                </el-table-column>
                                <el-table-column label="控制板号" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.ctrlBoard }}
                                </template>
                                </el-table-column>
                                <el-table-column label="控制指令" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.ctrlCmd }}
                                </template>
                                </el-table-column>
                                <el-table-column label="货道状态" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.status }}
                                </template>
                                </el-table-column>
                                <el-table-column label="排序" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.sort }}
                                </template>
                                </el-table-column>
                              
                                <el-table-column label="备注" width="110">
                                <template slot-scope="scope">
                                {{ scope.row.remark }}
                                </template>
                                </el-table-column>
                           

                                <el-table-column align="center" prop="created_at" label="操作" width="200">
                                    <template slot-scope="scope">
                                        <span class="el-tag el-tag--info el-tag--mini" style="cursor: pointer;" @click="handleEdit(scope.$index, scope.row)">
                                          {{ scope.row.isSet?'保存':"修改" }}
                                        </span>
                                        <span v-if="!scope.row.isSet" class="el-tag el-tag--danger el-tag--mini" style="cursor: pointer;" @click="handleDelete(scope.$index, scope.row)">
                                          删除
                                        </span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>

                        <div class="block">
                            <el-pagination
                                    :current-page="query.deviceAisleTemplateItem.currentPage"
                                    :page-sizes="[10, 20, 30, 40]"
                                    :page-size="query.deviceAisleTemplateItem.pageSize"
                                    layout="total, sizes, prev, pager, next, jumper"
                                    :total="query.deviceAisleTemplateItem.total"
                                    @size-change="handleQueryItemSizeChange"
                                    @current-change="handleQueryItemCurrentChange"
                            />
                        </div>
            </el-dialog>

        </div>

        <div>
             <el-dialog :title="titleMap[dialogStatus]" width="50%"  :visible.sync="dialogSelectGoodsFormVisible">

                 <el-radio-group v-model="radio">
                    <div class="block" v-for="goods in goodsList" :key="goods.id">
                       <el-image
                          style="width: 100px; height: 100px"
                          v-bind:src="goods.goodsImg"
                          >   
                          </el-image>
                          <el-radio v-bind:label="goods.id">{{goods.goodsName}}</el-radio>
                    </div>
                 </el-radio-group>
             
                <el-pagination
                  background
                  layout="prev, pager, next"
                   @current-change="handleQueryGoodsCurrentChange"
                  :total="query.goods.total"
                  :current-page="query.goods.currentPage"
                   :page-size="query.goods.pageSize"
                  >
                </el-pagination>
 
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogSelectGoodsFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="handleGetSelectedGoods">确 定</el-button>
                </div>
            </el-dialog>
        </div>

    </div>
</div>

</template>

<script>
    import { getList, doDelete, doEdit } from '@/api/deviceAisleTemplate/'
    import { getList as queryAislesTemplateItem, doDelete as removeTemplateItem, doEdit as editTemplateItem } from '@/api/deviceAisleTemplateItem/'
    import { getList as queryGoodsPagination   } from '@/api/goods'
    import { queryDeviceList, querySharedList, doEditShared, batchEdit, getMerchantList, bindMerchant,queryAllDeviceAisleBindSituation ,bindDeviceAisleMerchant} from '@/api/device/'
    import { queryGoodsPriceBy as getGoodsPrice   } from '@/api/goodsPrice'
    import { getDictionaryGroup , getReferencedDictionaryList  } from '@/api/dictionary'
    import { getList as getOrganList, querySubordinateOrgan } from '@/api/Organ'
    import { getOrganId, getTenantId, getOrganPath, getCurrentLoginUserId, handleBuildTreeDataStruct , getSelectedNodes , getSelectedNodesObject } from '@/api/utils'  
    import localStorageUtil from '@/utils/localStorageUtil'

    export default {       
        data() {
            return {
                list: null,
                listLoading: true,
                deviceAisleTemplateItemList:null,
                goodsList: null,
                total: 5,
                currentPage: 1,
                pageSize: 10,
                dialogFormVisible: false,
                dialogItemFormVisible: false,
                addForVisible: false,
                addForItemVisible:false,
                dialogQueryItemsFormVisible:false,
                dialogSelectGoodsFormVisible:false,
                fit:'contain',
                radio: 0,
                form: {
                    id:'',
                    name:'',
                    desc:'',
                    organId:'',
                    createBy:'',
                    updateBy:'',
                    createDate:'',
                    updateDate:'',
                    remark:'',
                    deleted:'',
                    deviceTypeId:'',
                    isDeleted:'',
                    organPath:''
                },
                deviceAisleTemplateItem:{
                    id:'',
                    templateId:'',
                    organId:'',
                    organPath:'',
                    goodsId:'',
                    goodsName:'',
                    goodsSpec:'',
                    goodsProductPlace:'',
                    goodsPrice:'',
                    goodsCost:'',
                    goodsDiscountPrice:'',
                    goodsImg:'',
                    aisleName:'',
                    printCount:'',
                    aisleType:'',
                    deleted:'',
                    isDone:'',
                    isHot:'',
                    ctrlBoard:'',
                    ctrlCmd:'',
                    status:'',
                    sort:'',
                    createBy:'',
                    updateBy:'',
                    createDate:'',
                    updateDate:'',
                    remark:'',
                    basePrice:'',
                    isDeleted:''
                    
                },
                // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
                titleMap: {
                    add: '新增',
                    edit: '编辑'
                },

                deviceTypeTree: {
                    valueIdSelect: {}, // 初始ID（可选）
                    valueId: {}, // 初始ID（可选）
                    props: { // 配置项（必选）
                        value: 'id',
                        label: 'deviceTypeName',
                        children: 'children',
                        title: '组织'
                        // disabled:true
                    },
                    isClearable: true, // 可清空（可选）
                    isAccordion: true  // 可收起（可选）
                },
                organTree:{
                    organvalueId: {}, // 初始ID（可选）
                    organProps: { // 配置项（必选）
                        value: 'id',
                        label: 'organName',
                        children: 'children',
                        title: '组织'
                    // disabled:true
                    },
                    organOptionData: [],
                    valueId: {}, // 初始ID（可选）
                },
                props: { // 配置项（必选）
                    value: 'id',
                    label: 'organName',
                    children: 'children',
                    title: '组织',
                    multiple: false,
                    checkStrictly: true,
                    emitPath:false
                    // disabled:true
                },
                optionData: [{ id: '1', parentId: '2', organName: '平台', children: [] }],

                // 新增和编辑弹框标题
                dialogStatus: '',
                query: {
                    params: {
                        id:'',
                        name:'',
                        desc:'',
                        organId:'',
                        createBy:'',
                        updateBy:'',
                        createDate:'',
                        updateDate:'',
                        remark:'',
                        deleted:'',
                        deviceTypeId:'',
                        isDeleted:'',
                        organPath:''
                    },
                    deviceAisleTemplateItem:{
                        templateId:'',
                        goodsName:'',
                        aisleName:'',
                        aisleType:'',
                        status:'',
                        organId:'',
                        organPath:'',
                        total: 5,
                        currentPage: 1,
                        pageSize: 10,

                    },
                    goods:{
                        id:'',
                        organId:'',
                        organPath:'',
                        organName:'',
                        typeId:'',
                        typePath:'',
                        goodsName:'',
                        supplierId:'',
                        goodsImg:'',
                        goodsDescribe:'',
                        unit:'',
                        unitValue:'',
                        productionPlace:'',
                        sys:'',
                        isDeleted:'',
                        quote:'',
                        createBy:'',
                        createDate:'',
                        updateBy:'',
                        updateDate:'',
                        remark:'',
                        total: 5,
                        currentPage: 1,
                        pageSize: 2,
                    },
                    timeValue: '',
                    options: [{
                        value: '1',
                        label: '黄金糕'
                    }, {
                        value: '2',
                        label: '双皮奶'
                    }],
                    templateItemStatusOptions :[],
                    templateItemAisleTypeOptions :[],
                    templateItemIsHotOptions:[],
                    value: ''
                }
            }
        },
        created() {
             this.initOrganTree(()=>{
                this.setOrganQueryType()
            })
            this.handleBuildDeviceAisleTemplateItemIsHotOptions()
            this.handleBuildDeviceAisleTemplateItemAisleTypeOptions()
            this.handleBuildDeviceAisleTemplateItemStatusOptions()
            this.initDeviceTypeTree()
            this.fetchData()
        },
        methods: {
            fetchData() {
                this.listLoading = true
                this.query.params.organPath = this.query.params.organPath||getOrganPath()

                getList(this.query.params , this.currentPage, this.pageSize).then(response => {
                    const data = response.data
                    this.total = data.totalCount
                this.pageSize = data.pageSize
                this.currentPage = data.currentPage
                this.list = data.entities
                this.listLoading = false
            })
            },
            handleSizeChange(val) {
                this.currentPage = 1
                this.pageSize = val
                 this.fetchData()
            },
            handleCurrentChange(val) {
                this.currentPage = val
                 this.fetchData()
            },
            // 新增
            handleAdd() {
                // 显示弹框
                this.dialogFormVisible = true
                // 新增弹框标题
                this.dialogStatus = 'add'

                this.form.id=''
                this.form.name=''
                this.form.desc=''
                this.form.organId=''
                this.form.createBy=''
                this.form.updateBy=''
                this.form.createDate=''
                this.form.updateDate=''
                this.form.remark=''
                this.form.deleted=''
                this.form.deviceTypeId=''
                this.form.isDeleted=''
                this.form.organPath=''
                this.addForVisible = false
            },
            // 编辑
            handleEdit(index, row) {
                console.log(index)
                console.log(row)
                this.form.id=row.id
                this.form.name=row.name
                this.form.desc=row.desc
                this.form.organId=row.organId
                this.form.createBy=row.createBy
                this.form.updateBy=row.updateBy
                this.form.createDate=row.createDate
                this.form.updateDate=row.updateDate
                this.form.remark=row.remark
                this.form.deleted=row.deleted
                this.form.deviceTypeId=row.deviceTypeId
                this.form.isDeleted=row.isDeleted
                this.form.organPath=row.organPath
                this.addForVisible = true
                // 显示弹框
                this.dialogFormVisible = true
                // 编辑弹框标题
                this.dialogStatus = 'edit'
            },
            handleDelete(index, row) {
                console.log(index)
                console.log(row)

                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    doDelete(row.id).then(response => {
                    const data = response.data
                    console.log(data)
                    if(data.status == 1){
                        this.$message({
                            type: 'success',
                            message: '操作成功!'
                        })
                        this.fetchData();
                    }else if(data.status == 403){
                        this.$message({
                            type: 'warning',
                            message: data.description
                        })
                }else{
                    this.$message({
                        type: 'info',
                        message: '操作失败!'
                    })
                }
            })
            }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
            })
            },
            handleEditSave() {

                doEdit(this.form).then(response => {
                    console.log(response)
                    const data = response.data
                    if(data.status){
                        this.$message({
                            type: 'success',
                            message: '操作成功!'
                        })
                     this.fetchData();
                    }else{
                        this.$message({
                            type: 'info',
                            message: '操作失败!'
                        })
                    }
                    this.listLoading = false
                    this.dialogFormVisible = false
                })
            },
            handleReset() {
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                })
            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
            },
            handleManageAisleDialogOpen(index, row){
                
                this.query.deviceAisleTemplateItem.templateId = row.id
                this.deviceAisleTemplateItem.templateId = row.id
                this.dialogQueryItemsFormVisible = true
                this.handleQueryAisleTemplateItem()
            },
            handleAddAisles(index, row){
                 // 显示弹框
                this.dialogItemFormVisible = true
                // 新增弹框标题
                this.dialogStatus = 'add'
                this.deviceAisleTemplateItem.id=''
                this.deviceAisleTemplateItem.organId=''
                this.deviceAisleTemplateItem.goodsId=''
                this.deviceAisleTemplateItem.goodsName=''
                this.deviceAisleTemplateItem.goodsSpec=''
                this.deviceAisleTemplateItem.goodsProductPlace=''
                this.deviceAisleTemplateItem.goodsPrice=''
                this.deviceAisleTemplateItem.goodsCost=''
                this.deviceAisleTemplateItem.goodsDiscountPrice=''
                this.deviceAisleTemplateItem.goodsImg=''
                this.deviceAisleTemplateItem.aisleName=''
                this.deviceAisleTemplateItem.printCount=''
                this.deviceAisleTemplateItem.aisleType=''
                this.deviceAisleTemplateItem.deleted=''
                this.deviceAisleTemplateItem.isDone=''
                this.deviceAisleTemplateItem.isHot=''
                this.deviceAisleTemplateItem.ctrlBoard=''
                this.deviceAisleTemplateItem.ctrlCmd=''
                this.deviceAisleTemplateItem.status=''
                this.deviceAisleTemplateItem.sort=''
                this.deviceAisleTemplateItem.createBy=''
                this.deviceAisleTemplateItem.updateBy=''
                this.deviceAisleTemplateItem.createDate=''
                this.deviceAisleTemplateItem.updateDate=''
                this.deviceAisleTemplateItem.remark=''
                this.deviceAisleTemplateItem.basePrice=''
                this.deviceAisleTemplateItem.isDeleted=''
                this.deviceAisleTemplateItem.organPath=''
                this.addForItemVisible = false

            },
            handleQueryAisles(index, row){
                this.dialogQueryItemsFormVisible = true
            },
            handleQueryAisleTemplateItem(){

                this.listLoading = true
                this.query.deviceAisleTemplateItem.organId = getOrganId()
                queryAislesTemplateItem( 
                    this.query.deviceAisleTemplateItem,
                    this.query.deviceAisleTemplateItem.currentPage,
                    this.query.deviceAisleTemplateItem.pageSize ).then(response => {
                        const data = response.data
                        this.query.deviceAisleTemplateItem.total = data.totalCount
                        this.query.deviceAisleTemplateItem.pageSize = data.pageSize
                        this.query.deviceAisleTemplateItem.currentPage = data.currentPage
                        this.deviceAisleTemplateItemList = data.entities
                        this.listLoading = false
                })

            },
            handleQueryItemSizeChange(val){

                this.query.deviceAisleTemplateItem.currentPage = 1
                this.query.deviceAisleTemplateItem.pageSize = val
                this.handleQueryAisleTemplateItem()
            },
            handleQueryItemCurrentChange(val){

                this.query.deviceAisleTemplateItem.currentPage = val
                this.handleQueryAisleTemplateItem()
            },
            handleBuildDeviceAisleTemplateItemStatusOptions(){

                getDictionaryGroup({sys:1, 
                    bigType:"DeviceAisleTemplateItemStatus", 
                    organId: getOrganId()}).then(response => {
                    const data = response.data
                    let templateItemStatusOptions = [];
                    for( let i =0; i < data.length; i ++ ){

                      let option = {}
                      option['value'] = data[i].value
                      option['label'] = data[i].desc
                      templateItemStatusOptions.push(option)
                    }
                    this.query.templateItemStatusOptions = templateItemStatusOptions

                })
          },

          handleBuildDeviceAisleTemplateItemAisleTypeOptions(){

                getDictionaryGroup({sys:1, 
                    bigType:"DeviceAisleTemplateItemAisleType", 
                    organId: getOrganId()}).then(response => {
                    const data = response.data
                    let templateItemAisleTypeOptions = [];
                    for( let i =0; i < data.length; i ++ ){

                      let option = {}
                      option['value'] = data[i].value
                      option['label'] = data[i].desc
                      templateItemAisleTypeOptions.push(option)
                    }
                    this.query.templateItemAisleTypeOptions = templateItemAisleTypeOptions
                    
                })
          },
          handleBuildDeviceAisleTemplateItemIsHotOptions(){

                getDictionaryGroup({sys:1, 
                    bigType:"DeviceAisleTemplateItemIsHot", 
                    organId: getOrganId()}).then(response => {
                    const data = response.data
                    let templateItemIsHotOptions = [];
                    for( let i =0; i < data.length; i ++ ){

                      let option = {}
                      option['value'] = data[i].value
                      option['label'] = data[i].desc
                      templateItemIsHotOptions.push(option)
                    }
                    this.query.templateItemIsHotOptions = templateItemIsHotOptions
                    
                })
            },
            handleSelectGoodsDialogOpen(){
                this.dialogSelectGoodsFormVisible = true
                this.handleSelectGoods()
            },
            handleSelectGoods(){

                this.listLoading = true
                //this.query.goods.organId = getOrganId()
                this.query.goods.organPath = getOrganPath()

                queryGoodsPagination(
                    this.query.goods,
                        this.query.goods.currentPage,
                        this.query.goods.pageSize ).then(response => {
                            
                            const data = response.data
                            this.query.goods.total = data.totalCount
                            this.query.goods.pageSize = data.pageSize
                            this.query.goods.currentPage = data.currentPage
                            this.goodsList = data.entities
                            this.listLoading = false
                })

            },
            handleQueryGoodsCurrentChange(val){
                this.query.goods.currentPage = val
                this.handleSelectGoods()
            },
            handleGetSelectedGoods(){

                let goods = null
                let goodsPrice = null
                for(let i =0; i < this.goodsList.length; i++){

                    if(this.goodsList[i].id == this.radio){

                        goods = this.goodsList[i]
                        this.listLoading = true
                        debugger
                        getGoodsPrice({}, getOrganId(), goods.id).then(response => {
                            
                            const result = response.data
                            if(result.data){
                                goodsPrice = result.data
                            }
                            this.deviceAisleTemplateItem.goodsProductPlace = goods.productionPlace
                            this.deviceAisleTemplateItem.goodsPrice = goodsPrice.price
                            this.deviceAisleTemplateItem.goodsCost = goodsPrice.costPrice
                            this.deviceAisleTemplateItem.goodsDiscountPrice = goodsPrice.discountPrice
                            this.deviceAisleTemplateItem.basePrice = goodsPrice.suggestedRetailPrice
                            
                            this.listLoading = false
                        })
                        break;
                    }
                }     
                this.deviceAisleTemplateItem.goodsId = goods.id
                this.deviceAisleTemplateItem.goodsName = goods.goodsName
                this.deviceAisleTemplateItem.goodsSpec = goods.goodsDescribe

                this.deviceAisleTemplateItem.goodsImg = goods.goodsImg
                this.dialogSelectGoodsFormVisible = false
            },
            handleTemplateItemEditSave(){

                this.deviceAisleTemplateItem.organId = getOrganId()
                this.deviceAisleTemplateItem.organPath = getOrganPath()
                this.listLoading = true

                editTemplateItem(this.deviceAisleTemplateItem).then(response => {
                    console.log(response)
                    const data = response.data
                    if( data.status ){
                        this.$message({
                            type: 'success',
                            message: '操作成功!'
                        })
                     this.handleQueryAisleTemplateItem()
                    }else{
                        this.$message({
                            type: 'info',
                            message: '操作失败!'
                        })
                    }
                    this.listLoading = false
                    this.dialogFormVisible = false
                })
            },
            initDeviceTypeTree() {
                this.listLoading = true
                queryDeviceList({ organPath: getOrganPath() }).then(response => {
                    console.log(response)
                    const data = response.data
                    this.deviceTypeTree.optionData = handleBuildTreeDataStruct(data, 'id', 'parentId')
                    this.listLoading = false
                })
            },
            initOrganTree() {
                this.listLoading = true
                querySubordinateOrgan({ organPath: getOrganPath() }).then(response => {
                    console.log(response)
                    const data = response.data.data
                    this.organTree.organOptionData = handleBuildTreeDataStruct(data, 'id', 'parentId')
                    this.listLoading = false
                })
            },
            getValueSelect(value) {
              if (value == null) {
                this.query.params.type = '';
              } else {
                this.valueIdSelect = value
                this.query.params.type = value.deviceTypeCode
              }
            },
            getDeviceTypeSelected(value) {
                  debugger
                  if (value == null) {
                    this.form.deviceTypeId = '';
                  } else {
                    this.valueIdSelect = value
                    this.form.deviceTypeId = value.id
                  }
            },
            getOrganSelected(value){
                console.log(value)
                debugger
                if (value == null) {
                    this.query.params.organId = '';
                    this.query.params.organPath = '';

                } else {
                    this.form.organId = value.id;
                    this.form.organPath = value.organPath;
                }
            },
            getValueIdSelectOrgan(value) {
              console.log(value)
              if (value == null) {
                this.query.params.organId = '';
              } else {
                this.query.params.organId = value.id;
              }
            },
            initOrganTree(fn) {
              this.listLoading = true
              querySubordinateOrgan({ organId: getOrganId() }).then(response => {
                  console.log(response)
                  const data = response.data.data
                  this.optionData = handleBuildTreeDataStruct(data, 'id', 'parentId')
                  this.listLoading = false
                  fn()
              })
            },
            setOrganQueryType(){
              this.organQueryModelChange(localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL"))
            },
            selectOrgan(nodes){
              let nodesInfo = this.$refs['organTree'].getCheckedNodes()
              let that = this
              this.query.params.organPath = ''
              this.query.params.organIds = []
              if (this.props.multiple) {
                  this.query.params.organIds = []
                  if (nodesInfo.length) {
                      nodesInfo.forEach(function(element){
                          that.query.params.organIds.push(element.data.id)
                      })
                  }
              } else {             
                  this.query.params.organPath = nodesInfo[0].data.organPath
              }
            },
            organQueryModelChange(organQueryModel) {
              if(organQueryModel == 'selected') {
                  this.props.multiple=true
              }else if(organQueryModel == 'selfAndSub') {
                  this.props.multiple=false
              }
            }

        }
    }
</script>
